package com.xpu.cos.controller;

import java.util.Arrays;
import java.util.Map;

import com.xpu.cos.result.Result;
import com.xpu.cos.result.ResultCodeEnum;
import com.xpu.cos.service.PurchaseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.xpu.cos.entity.Purchase;
import com.xpu.cos.utils.PageUtils;




/**
 *
 *
 * @author wsh
 * @email wsh@gmail.com
 * @date 2024-01-04 15:12:54
 */
@RestController
@RequestMapping("/cos/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return Result.ok().build(page, ResultCodeEnum.SUCCESS);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public Result info(@PathVariable("id") Integer id){
        Purchase purchase = purchaseService.getById(id);

        return Result.ok().build(purchase, ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public Result save(@RequestBody Purchase purchase){
        purchaseService.save(purchase);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public Result update(@RequestBody Purchase purchase){
        purchaseService.updateById(purchase);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer[] ids){
        purchaseService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
